<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>提示</title>
    </title>
    <!-- <link rel="stylesheet" href="https://res.wx.qq.com/open/libs/weui/2.0.1/weui.min.css">
    <script type="text/javascript" src="https://res.wx.qq.com/t/wx_fed/cdn_libs/res/weui/1.2.3/weui.min.js"></script> -->

    
    <link rel="stylesheet" href="./weui.min.css">
    <script type="text/javascript" src="./weui.min.js"></script>

</head>

<body>
    <script>
        /*
   设置cookie
   name:键
   value:值
   expire:过期时间
   */
        function setCookie(name, value, expire) {
            var exp = new Date();
            exp.setTime(exp.getTime() + expire * 24 * 60 * 60 * 1000 * 1);
            document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
        };
        //根据键获取cookie
        function getCookie(name) {
            var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
            if (arr = document.cookie.match(reg))
                return unescape(arr[2]);
            else
                return null;
        };
        //删除cookie
        function delCookie(name) {
            var exp = new Date();
            exp.setTime(exp.getTime() - 1);
            var cval = getCookie(name);
            if (cval != null)
                document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString() + ";Path=/";
        };


        // function getQueryVariable(variable){
        //     var url=window.location.href;
        //     var str=url.split('?');
        //     var query=str[1];
        //     var vars=query.split('&');
        //     console.log(query,str,vars);
        //     for (var i=0;i<vars.length;i++) {
        //         var pair = vars[i].split("=");
        //         console.log(pair);
        //         if(pair[0] == variable){
        //             return pair[1];
        //         }
        //     }
        //     return(false);
        // }

        // 当重定向url中含有参数时，会解析失败，如 /mp/login?code=xxxxxxxxxx&state=, 解析出来：/mp/login
        // 换成 cookie 方式
        // console.log(getQueryVariable('redirect'));
        // console.log(getQueryVariable("redirect"));
        // var redirectUrl = getQueryVariable('redirect');

        var redirectUrl = window.location.href.split("redirect=")[1]
        console.log(redirectUrl);



        function toTest(){
            console.log('yes');
            window.location.replace(redirectUrl);
        }
        function toRelese() {
            console.log('no');
            delCookie("env");
            window.location.replace(redirectUrl);
        }
        weui.confirm('你正在访问测试版，是否继续？', {
            title: '提示',
            buttons: [{
                label: '访问正式版',
                type: 'default',
                onClick: function(){ console.log('no');toRelese(); }
            }, {
                label: '确定',
                type: 'primary',
                onClick: function(){ console.log('yes');toTest(); }
            }]
        });
        // weui.confirm('你正在访问测试版，是否继续？', function () {
        //     console.log('yes');
        //     window.location.replace("/");
        // }, function () {
        //     console.log('no');
        //     delCookie("env");
        //     window.location.replace("/");
        // });
    </script>

</body>

</html>